#!/bin/bash

#! amount args
# ${_is_amount_arg} ${NARGS} min_equ max_equ
# if [ $? -ne 0 ]; then
#     plt_info "${_is_amount_arg}:: be return 1"
#     return 1
# fi
#! normalize ptr_path -> absolut path
# ptr_path=$1
# ptr_path=$(${_abs_path} $PPWD "ptr_path") #ptr args
#! variables for cr_f_dir_insert_
# fn_name=$(${_prs_f} -n ${arg_path})
# root_path=$(${_prs_f} -d ${arg_path})
#! search in array
# [[ " ${arr[*]} " =~ " $1 " ]] && echo "true" || echo "false"
#! ${array[@]:1} all from 1 member arr

# echo -e "${GREEN}\${g_args[@]} = ${g_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${e_args[@]} = ${e_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${f_args[@]} = ${f_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${ARGS[@]} = ${ARGS[*]}${NORMAL}"     #print variable
# echo -e "${GREEN}\${ARGS0} = ${ARGS0}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS1} = ${ARGS1}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS2} = ${ARGS2}${NORMAL}"         #print variable

# echo -e "${GREEN}\${dir_fns_} = ${dir_fns_}${NORMAL}" #print variable

echo -e "${GREEN}\${local_var_wrap_arr[@]} = ${local_var_wrap_arr[*]}${NORMAL}" #print variable
echo -e "${GREEN}\${local_var_fn_arr[@]} = ${local_var_fn_arr[*]}${NORMAL}"     #print variable

# echo -e "${GREEN}\$ratis = $ratis${NORMAL}" #print variable

# echo "that ${FNN}.sal"

list_strong_cntls=(list_ del_)

for item in "${list_strong_cntls[@]}"; do
    if [ -z "$(eval echo \$"$item")" ]; then
        plt_info "from ${FNN}() $item is empty :: be return 1"
        return 1
    fi
done

if ([ "${dpl_:-0}" -eq 1 ] && [ "${bcp_:-0}" -ne 1 ]) || ([ "${dpl_:-0}" -ne 1 ] && [ "${bcp_:-0}" -eq 1 ]); then
    :
else
    plt_info "from ${FNN}() once dpl_ or bcp_ mast be able :: be return 1"
    return 1
fi

#?--------------------------------------------------------
#?---------------------------------------------
#?---------------------------------------

for item in $(f2e "${list_}"); do
    p_arr=()
    s3parr_ --_str "${item}" --_del "${del_}" --_parr p_arr 1>/dev/null

    path_src="${p_arr[0]}"
    dir_src=$(dirname "${path_src}")
    node_src=$(basename "${path_src}")

    echo -e "${GREEN}\$dir_src = $dir_src${NORMAL}"
    echo -e "${GREEN}\$node_src = $node_src${NORMAL}"

    path_tar=${p_arr[1]}.tar.gz
    dir_tar=$(dirname "${path_tar}")
    file_tar=$(basename "${path_tar}").tar.gz

    echo -e "${GREEN}\$dir_tar = $dir_tar${NORMAL}"
    echo -e "${GREEN}\$file_tar = $file_tar${NORMAL}"

    [ -n "${path_tar}" ] || {
        plt_info "from ${FNN}() ISEMPTY : \${path_tar} :: be return 1"
        return 1
    }

    [ -d "${dir_tar}" ] || {
        plt_info "from ${FNN}() :: NOTDIR : \${dir_tar}=${dir_tar} :: be return 1"
        return 1
    }

    [ -f "${path_src}" ] || [ -d "${path_src}" ] || {
        plt_info "from ${FNN}() NOTFILE or NOTDIR : \${path_src}=${path_src} :: be return 1"
        return 1
    }

    # cd "${dir_src}"
    # tar -czvf f1._tmp_ f1
    # mv -vf f1.tmp "${dir_tar}"/f1.tar.gz

    # cd "${dir_tar}"
    # tar -xzvf f1.tar.gz -C "${dir_src}"

    if [ "${bcp_}" -eq 1 ]; then

        if [ -f "${path_src}" ]; then

            cd "${dir_src}" || {
                plt_info "FAIL : cd ${dir_src} :: be return 1"
                return 1
            }

            tar -czvf "${node_src}"._tmp_ "${node_src}"

            mv -vf "${node_src}"._tmp_ "${path_tar}"

        elif [ -d "${path_src}" ]; then

            cd "${dir_src}" || {
                plt_info "FAIL : cd ${dir_src} :: be return 1"
                return 1
            }

            tar -czvf "${node_src}"._tmp_ "${node_src}"

            mv -vf "${node_src}"._tmp_ "${path_tar}"

        fi

    elif [ "${dpl_}" -eq 1 ]; then

        if [ -f "${path_src}" ]; then

            cd "${dir_tar}" || {
                plt_info "FAIL : cd ${dir_tar} :: be return 1"
                return 1
            }

            tar -xzvf "${file_tar}" -C "${dir_src}"

        elif [ -d "${path_src}" ]; then

            cd "${dir_tar}" || {
                plt_info "FAIL : cd ${dir_tar} :: be return 1"
                return 1
            }

            tar -xzvf "${file_tar}" -C "${dir_src}"

        fi

    fi

done

#?---------------------------------------
#?---------------------------------------------
#?--------------------------------------------------------
